home *** CD-ROM | disk | FTP | other *** search
- Path: andrew.cmu.edu!sangp+
- From: "Sang Hyun Park, Shawn" <sangp+@andrew.cmu.edu>
- Newsgroups: comp.lang.c++
- Subject: Reading binary file in MSVC++2.1 ??
- Date: Sun, 3 Mar 1996 05:16:41 -0500
- Organization: Junior, Social & Decision Sciences, Carnegie Mellon, Pittsburgh, PA
- Message-ID: <0lCL69200YUf0EAnE0@andrew.cmu.edu>
- NNTP-Posting-Host: po6.andrew.cmu.edu
-
-
- I'm trying to read in a binary file into an array of fixed, but large size.
- (the size of files i'm reading in is approx. 12k)
- I tried two different ways to read in the file, but i kept getting error
- messages. could someone take a look it and suggest me what i'm doing wrong
- or missing in the code? Or please tell me if there is a better way to
- accomplish the task.
-
- another question i have is, how can i display the content of the binary
- file on screen? there is some header information in the input file that
- i need to skip, and i want to see how many bytes i need to skip from the
- beginning of the file.
-
- i'm doing this under WinNT with MSVC++ 2.1
-
- thank you,
- shawn park
-
-
- trial-1
- ------------------------------------------------------------------------
- #include <fstream.h>
- #include <string.h>
-
- void main(void)
- {
- short buf[2000]; // arbitrary size for trial
-
- ifstream ins("filename.bin");
- ins.get(buf, 2000); *
-
- }
- --------------------------------------
- "filename.bin" is the name of the binary file.
-
- Error message i got was:
- * `class istream &istream::get(char*,int,char)':
- cannot convert parameter 1 from 'short[2000]' to 'char*'
-
- so, i think it might be that i can only use ins.get to read in chars, and
- no binary chars. is that correct?
-
-
-
- trial-2
- -------------------------------------------------------------
- #include <afx.h>
- #include <iostream.h>
-
- const size_t BUFSIZE = 256;
-
- // Open a CFile associated with a specific file
- CFile fin("Filename.bin", CFile::modeRead);
-
- // Open test output file
- CFile fout("output.xxx", CFile::modeWrite |
- CFile::modeCreate);
-
- // Read from one file and write to the other
- short buf[BUFSIZE];
- int n = fin.Read(buf, BUFSIZE);
-
- while (n > 0)
- {
- fout.Write(buf, n);
- n = fin.Read(buf, BUFSIZE);
- };
-
- fin.Close();
- fout.Close();
-
- }
- ------------------------------------------
-
- according to the book i have, i can read in binary information using the
- CFile class (as above), but i kept getting this error message i couldn't
- understand.
-
-
- 1) nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol
- "__beginthreadex"
- 2) nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol
- "__endthreadex"
-
-
- i thought i wasn't dealing with thread. what is wrong with this method of
- reading in the file?
-
-
-
-
-
-